<?php

// @formatter:off
/**
 * @file WCRepresentationKeyword.abs.php
 * @author Alejandro Dario Simi
 * @date $Date: 2014-05-04 01:33:52 +0000 (Sun, 04 May 2014) $
 *
 * $Id: WCRepresentationKeyword.abs.php 111 2014-05-04 01:33:52Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/includes/representations/WCRepresentationKeyword.abs.php $
 */
// @formatter:on

/**
 * @abstract
 * @class WCRepresentationKeyword
 */
abstract class WCRepresentationKeyword extends WCRepresentation {
	//
	// Protected properties.
	/**
	 * @var string[] This variable holds the list of columns that cannot be
	 * directly modified by the pseudo-method __set().
	 */
	protected $_PropertiesReadOnly = array(
		"id",
		"keyword"
	);
	//
	// Magic methods.
	public function __toString() {
		return $this->ok() ? "{$this->name()} ({$this->id()}[k:{$this->keyword}])" : "broken item";
	}
	//
	// Public methods.
	public function keyword() {
		return $this->keyword;
	}
	public function reload() {
		return parent::reload();
	}
	public function setKeyword($keyword) {
		$out = false;
		//
		// @{
		$stmt = null;
		$stmtId = __CLASS__."::".__FUNCTION__."[{$this->_PropertiesTable}]";
		if($this->_db->has($stmtId)) {
			$stmt = $this->_db->get($stmtId);
		} else {
			$query = "update  {$this->_dbprefix}{$this->_PropertiesTable}\n";
			$query .= "set     {$this->_PropertiesPrefix}keyword = :keyword\n";
			$query .= "where   {$this->_PropertiesPrefix}id      = :id\n";

			$stmt = $this->_db->prepare($stmtId, $query);
		}
		// @}

		$params = array(
			":id" => $this->id,
			":keyword" => $keyword
		);

		if($stmt->execute($params)) {
			$out = true;
		}

		$this->reload();

		return $out;
	}
}
